<?php
namespace cms\modules\v1\controllers;

use cms\modules\v1\models\access\ModuleActions;
use common\models\config\ConfigAddress;
use common\models\Functions;
use Yii;
use yii\filters\auth\HttpHeaderAuth;
use yii\helpers\ArrayHelper;


/**
 * Default controller for the `v1` module
 */
class AddressController extends DefaultController
{

    public $modelClass = '';
    public function behaviors()
    {
        return ArrayHelper::merge(parent::behaviors(), [
            'authenticator' => [
                'class' =>  HttpHeaderAuth::className(),    //head头部验证
                'header' => 'access-token',
                'optional' => [

                ]
            ]
        ]);
    }

    public function actionList($p = 0){
        if (Yii::$app->request->isGet) {
            return (new ConfigAddress())->getList($p);
        }
    }

    //省
    public function actionProvinceMap () {
        $check = (new ModuleActions())->checkActions();
        if ($check !== true) {
            return Functions::formatRestAPI(1, $check);
        }
        if (Yii::$app->request->isGet) {
            return Functions::formatRestAPI(0,'',(new ConfigAddress())->getProvinceInfo());
        }
    }

    //市
    public function actionCityMap ($pid = 0, $search = false) {
        $check = (new ModuleActions())->checkActions();
        if ($check !== true) {
            return Functions::formatRestAPI(1, $check);
        }
        if (Yii::$app->request->isGet) {
            return Functions::formatRestAPI(0,'',(new ConfigAddress())->getCityInfo($pid,$search));
        }
    }

    //区
    public function actionAreaMap ($pid = 0) {
        $check = (new ModuleActions())->checkActions();
        if ($check !== true) {
            return Functions::formatRestAPI(1, $check);
        }
        if (Yii::$app->request->isGet) {
            return Functions::formatRestAPI(0,'',(new ConfigAddress())->getAreaInfo($pid));
        }
    }

}
